﻿using MesBSW.BLL.Mes;
using MesBSW.DAL.MesDB;
using MesBSW.Tools;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MesBSW.View.Dialog.Language
{
    public partial class AddLanguageInfoDia : Form
    {
        public AddLanguageInfoDia()
        {
            InitializeComponent();
            LanguageTools.ChangeControlTextForLangType(this, MainFrm.CurrLanguage);
        }


        #region "内部变量"
        private LanguageControler _ctrl = new LanguageControler();
        
        #endregion

        #region "控件事件"
        /// <summary>
        /// 界面读入时，系统都分配一个最新语言代号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddLanguageInfoDia_Load(object sender, EventArgs e)
        {
            string langCode = this._ctrl.GetMaxCodeForLanguageInfo();
            this.txtLangCode.Text = langCode;
        }

        /// <summary>
        /// 关闭本界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 添加新的多语言种类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSave_Click(object sender, EventArgs e)
        {
            LanguageInfo saveEntity = this.InitSaveEntity();
            try
            {
                int count = this._ctrl.AddLanguageInfo(saveEntity);
                UIMessageBox.ShowSuccess("多语言种类保存成功！");
                this.Close();
            }
            catch (Exception ex)
            {
                UIMessageBox.ShowError("多语言种类保存失败！" + "\r\n" + ex.Message);
            }
        }
        #endregion

        #region "内部方法"
        /// <summary>
        /// 根据用户在界面填入的信息初始化LanguageInfo实体
        /// </summary>
        /// <returns></returns>
        private LanguageInfo InitSaveEntity()
        {
            LanguageInfo resBean = new LanguageInfo 
            {
                id = 0,
                lang_code = this.txtLangCode.Text,
                lang_name_cn = this.txtLangNameCN.Text,
                lang_name_en = this.txtLangNameEN.Text
            };
            return resBean;
        }


        #endregion

        
    }
}
